<%@ page contentType="text/html; charset=utf-8"%>
<form id="dform7">
<table id="mytable" border="0" cellpadding="0" cellspacing="1" width="100%">
	<caption>
		<h1>
			<strong>下发新文件</strong>
		</h1>
	</caption>
	<tr>
		<th width="11%">
			选择文件
		</th>
		<td colspan="3">
			<fieldset>
				<legend>选择一个文件</legend>
				<div id="file-upload-jpg"></div>
				<div id="output1" />
			</fieldset>
		</td>
	</tr>
	<tr>
		<th></th>
		<td width="30%">
			部门
		</td>
		<td width="30%">
			角色
		</td>
		<td width="30%">
			用户定义部门
		</td>
	</tr>
	
	<tr>
		<th>
			权限
		</th>
		<td width="30%">
			<select multiple="multiple" size="15" name="departments[]" id="groups">
			</select>
		</td>
		<td width="30%">
			<select  multiple="multiple" id="roles" name="roles[]" size="15">
			</select>
		</td>
		<td width="30%">
			<select  name="customOrganization" size="15" id="custs">
			</select>
		</td>
	</tr>
	
</table>
</form>
<script type="text/javascript">
$(function() {
	$.getJSON("admin/department/department!listuser", {
		"listAll" : true
	}, function(data, textStatus, jqXHR) {
		var depts = data.rows;
		var cnar = $("#groups");
		var depts = data.rows;
		$.each(depts, function(index, item) {
			var opt = $("<option></option>");
			opt.val(item.id);
			opt.text(item.name);
			cnar.append(opt);
		});
	});
	$.getJSON("admin/role/role!gets", {
		"listAll" : true
	}, function(data, textStatus, jqXHR) {
		var cnar = $("#roles");
		var depts = data.rows;
		$.each(depts, function(index, item) {
			var opt = $("<option></option>");
			opt.val(item.id);
			opt.text(item.name);
			cnar.append(opt);
		});
	});
	$.getJSON("fileflow/group/custom-organization!gets", {
		"listAll" : true
	}, function(data, textStatus, jqXHR) {
		var cnar = $("#custs");
		var depts = data.rows;
		$.each(depts, function(index, item) {
			var opt = $("<option></option>");
			opt.val(item.id);
			opt.text(item.name);
			cnar.append(opt);
		});
	});
	(function createUploader() {
		var jpguploder = new qq.FileUploader( {
			element : document.getElementById('file-upload-jpg'),
			action : 'viewfile/save',
			//params: {"workflowId":${param.workflowId}},
			fileDataName : "imageFile",
			allowedExtensions : [ 'pdf', 'doc', 'xls', 'ppt', 'pps' ],
			debug : true,
			onComplete : function(id, fileName, resp) {
				if (window.console)
					console.log(resp);
				$("#output1").empty();
				$("#output1").append("文件 :" + fileName + "上传完毕!<br/>");
				$("#output1").append(fileName);
			},
			onSubmit: function(id, fileName){
				var groups = $("#groups option:selected");
				var par = {};
				$.each(groups,function(index,group){
					var idname="viewFile.departments["+index+"].id";
					var nname = "viewFile.departments["+index+"].name";
					par[idname]=group.value;
					par[nname]=group.text;
				});
				var roles = $("#roles option:selected");
				
				$.each(roles, function(index, role){
                    var idname="viewFile.roles["+index+"].id";
                    var nname="viewFile.roles["+index+"].name";
					par[idname]=role.value;
					par[nname]=role.text;
				});
				
				var custxx = $("#custs");
				if(custxx.val()!=null)
				par['viewFile.customOrganization.id']= custxx.val();
				
				jpguploder.setParams(par);				
				return true;
			}
		});
	})();	
});
</script>